#!/bin/bash

export OS_CLOUD={{ tempest_cloud_name }}

openstack network list -c Name -f value | grep -q -e "^{{ tobiko_floating_ip_network }}$"
if [ $? -eq 0 ]; then
    exit 0
fi

openstack network create {{ tobiko_floating_ip_network }} --external \
{% if public_physical_network != '' %}
    --provider-network-type {{ public_network_type }} \
    {% if public_segmentation_id != '' %}
    --provider-segment {{ public_segmentation_id }} \
    {% endif %}
    --provider-physical-network {{ public_physical_network }}
{% endif %}

openstack subnet create ext-subnet \
    --allocation-pool \
    start={{ public_network_pool_start }},end={{ public_network_pool_end }} \
    --no-dhcp \
    --gateway {{ public_network_gateway }} \
    --network {{ tobiko_floating_ip_network }} \
    --subnet-range {{ floating_ip_cidr }}
